package com.szxx.suit;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 分析结果包装类 <br>
 *
 * @author Ambrose
 */
public abstract class AbstractAnalysisResult implements Comparable<AbstractAnalysisResult>, Cloneable {

	protected static Logger logger = LoggerFactory.getLogger(AbstractAnalysisResult.class);
	
	/**
	 * 分析结果对应的牌型
	 * 
	 * @return
	 */
	public abstract AbstractSuitType getType();
	
	/**
	 * 比较大小，-1 小于 0 等于 1大于 compareTo
	 */
	@Override
	public int compareTo(AbstractAnalysisResult compareTo) {
		if (compareTo == null || compareTo.getType() == null) {
			logger.error("compareTo compareTo == null || compareTo.getType() == null !!!");
			return 1;
		} else if (this.getType() == null) {
			logger.error("compareTo this.getType() == null !!!");
			return -1;
		} else {
			// 先比较一下权重
			int weight = this.getType().getWeight() - compareTo.getType().getWeight();
			if (weight == 0) {
				return doCompareTo(compareTo);
			} else {
				return weight;
			}
		}
	}
	
	@Override
	public AbstractAnalysisResult clone() {
		try {
			return (AbstractAnalysisResult) super.clone();
		} catch (CloneNotSupportedException e) {
			logger.error("", e);
		}
		return null;
	}

	/**
	 * 比较大小，-1 小于 0 等于 1大于 compareTo
	 * 
	 * @param compareTo 不会为null
	 * @return
	 */
	protected abstract int doCompareTo(AbstractAnalysisResult compareTo);

}
